<?php
/**
 * 熵巡 - 企业级氚云OpenAPI数据管理平台
 * 开发归属 Alyr.net
 * 氚云API数据查询 - 查询氚云业务数据分页接口
 * 尊重劳动成果是一种美德
 */

session_start();

// 检查登录状态
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) {
    header('Content-Type: application/json');
    echo json_encode(['success' => false, 'message' => '请先登录']);
    exit;
}

// 引入配置文件和客户端类
require_once '../config.php';
require_once '../classes/H3OpenApiClient.php';

header('Content-Type: application/json');

try {
    $config = require '../config.php';
    $client = new H3OpenApiClient($config);
    
    // 获取查询参数
    $pageIndex = intval($_GET['page'] ?? 1);
    $pageSize = intval($_GET['size'] ?? 20);
    $fromRowNum = ($pageIndex - 1) * $pageSize;
    $toRowNum = $fromRowNum + $pageSize - 1;
    
    // 查询数据
    $filter = [
        'FromRowNum' => $fromRowNum,
        'ToRowNum' => $toRowNum
    ];
    
    $result = $client->loadBizObjects($config['schema_code'], $filter);
    
    echo json_encode([
        'success' => true,
        'message' => '查询成功',
        'data' => $result,
        'count' => count($result),
        'page' => $pageIndex,
        'size' => $pageSize
    ]);
    
} catch (Exception $e) {
    echo json_encode([
        'success' => false,
        'message' => '查询失败: ' . $e->getMessage()
    ]);
}
?>